package com.pachong.android.frameworkbase.dialog;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.pachong.android.frameworkbase.dialog.base.IOSAlertBaseFragment;

import java.util.ArrayList;
import java.util.List;

import com.pachong.android.frameworkbase.R;

/**
 * IOS Style Alert List Dialog Fragment
 *
 * @Author: PengWeiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016-06-21
 * @Version: 1.0.0
 */
public class IOSAlertListFragment extends IOSAlertBaseFragment {

    private List<String> mActionList = new ArrayList<>();
    private AdapterView.OnItemClickListener mActionClickedListener;
    private ListView mListView;

    @Override
    public View createDialogContentView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_ios_alert_list, null);
        mListView = (ListView) view.findViewById(R.id.listview);

        if (mActionList != null && mActionList.size() > 0) {
            mListView.setAdapter(new ArrayAdapter<>(getActivity(),
                    R.layout.item_fragment_ios_alert_list, mActionList));
            mListView.setOnItemClickListener(mActionClickedListener);
        } else {
            throw new RuntimeException("操作列表不可以为空");
        }

        return view;
    }


    public IOSAlertListFragment setActionList(AdapterView.OnItemClickListener listener, String... actionArr) {
        mActionClickedListener = listener;
        if (actionArr != null && actionArr.length > 0) {
            for (String action : actionArr) {
                mActionList.add(action);
            }
        }
        return this;
    }


    public IOSAlertListFragment setActionList(AdapterView.OnItemClickListener listener, List<String> actionList) {
        mActionClickedListener = listener;
        if (actionList != null && actionList.size() > 0) {
            for (String action : actionList) {
                mActionList.add(action);
            }
        }
        return this;
    }


}
